<style lang="less" scoped>
.panel {
  margin-bottom: 10px;
  &-title {
    display: flex;
    padding: 10px;
    border-bottom: 0.1px solid #eaeaea;
    background: white;

    &__label {
    }
    &__value {
      flex: 1;
      font-size: 16px;
      align-items: center;
    }
  }
  &-content {
    margin-bottom: 10px;
    background: white;

    &__item {
      display: flex;
      padding: 10px 10px 0 10px;
      font-size: 14px;
      &-label {
        color: #666;
      }
      &-value {
        flex: 1;
        padding-left: 15px;
        color: #333;
      }
    }
  }
}
</style>

<template>
  <div>
    <load v-if="loading"></load>
    <div class="info" v-else-if="items.length==0">暂无数据</div>
    <div class="panel">
      <template v-for="(item, index) in items" wx:key="unique">
        <!-- title -->
        <div class="panel-title" :key="'title'+index">
          <div class="panel-title__label">
          </div>
          <div class="panel-title__value avator">
            <image class="avator-img" v-if="item.avatar" :src="item.avatar" />
            <text-to-avator v-else :text="item.StockName"></text-to-avator>
            <span class="primaryC" @click="itemClick(item)">{{item.StockName}}</span>
          </div>
          <div class="panel-title__right"></div>
        </div>
        <!-- content -->
        <div class="panel-content" :key="'content'+index">
          <div class="panel-content__item">
            <div class="panel-content__item-label">持股比例</div>
            <div class="panel-content__item-value">{{item.StockPercent||'-'}}</div>
            <div class="panel-content__item-right"></div>
          </div>
          <div class="panel-content__item">
            <div class="panel-content__item-label">股东类型</div>
            <div class="panel-content__item-value">{{item.StockType||'-'}}</div>
            <div class="panel-content__item-right"></div>
          </div>
          <div class="panel-content__item">
            <div class="panel-content__item-label">认缴出资额（万元）</div>
            <div class="panel-content__item-value">{{item.ShouldCapi||'-'}}</div>
            <div class="panel-content__item-right"></div>
          </div>
          <div class="panel-content__item">
            <div class="panel-content__item-label">认缴出资日期</div>
            <div class="panel-content__item-value">{{item.ShoudDate||'-'}}</div>
          </div>
        </div>
      </template>
    </div>
  </div>
</template>
<script>
import Load from '@/components/load';
import TextToAvator from '@/components/textToAvator';

export default {
  components: {
    Load,
    TextToAvator
  },
  data() {
    return {
      items: []
    };
  },
  onLoad() {
    this.getInfos();
  },
  onUnload() {
    this.items = [];
  },
  computed: {
    loading() {
      return this.$store.getters.loading;
    }
  },
  methods: {
    changeCount(count) {
      const item = { type: 'gudong', count };
      this.$emit('countChange', item);
    },
    async getInfos() {
      try {
        this.items = this.$store.getters.companyInfo.Company.Partners;
        this.changeCount(this.items.length || 0);
      } catch (error) {}
    },
    isFaren(KeyNo) {
      if (!KeyNo) {
        return false;
      }
      return KeyNo.indexOf('p') === 0;
    },
    itemClick(item) {
      return; //本地获取数据，路由信息有问题，待更新
      const isFaren = this.isFaren(item.KeyNo);
      if (isFaren) {
        // 法人
        const Oper = {
          Name: item.StockName,
          KeyNo: item.KeyNo
        };
        this.$router.push({
          path: '/pages/base/faren/main',
          query: {
            Oper: JSON.stringify(Oper)
          }
        });
        return;
      }
      // 企业
      this.$router.push({
        path: '/pages/company/main',
        query: {
          unique: item.KeyNo
        }
      });
    }
  }
};
</script>
